package com.gitee.elf.api.common

import com.gitee.elf.core.data.Data
import com.gitee.elf.core.entity.AbstractProxyEntity
import com.gitee.elf.core.entity.EntityInstance

open class MetaWatcher<T : Data>(val name: String, instance: EntityInstance) {

    constructor(name: String, entity: AbstractProxyEntity<*>) : this(name, entity.instance)

    @Suppress("UNCHECKED_CAST")
    var value = (instance.metadataContainer.get(name)?.bind) as T

    fun set(value: T) {
        this.value = value
        onUpdate(value)
    }

    open fun onUpdate(value: T) {

    }

    fun get(): T {
        return this.value
    }


}